package reci.journal.utils;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

/*
 * Copyright (C) 2014 ReciGames
 * See notice in reci.journal.Main.java.
 */

/**matches and replaces patterns in a string*/
public class Macro
{
	/**Map< pattern , replacement >*/
	protected static Map<String,String> rules=new HashMap<>();
	
	public static void setRules(Map<String,String> r)
	{
		rules=r;
	}
	
	/**
	 * @param line
	 * @return 'line' with replacements made
	 */
	public static String process(String line)
	{
		for(Entry<String,String> entry : rules.entrySet())
		{
			line=line.replace(entry.getKey(),entry.getValue());
		}
		
		return line;
	}
}
